package cn.yuemouren.security.core.authorize;

import cn.yuemouren.security.core.properties.SecurityConstants;
import cn.yuemouren.security.core.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component;

/**
 * @Author: Timi
 * @Description: 核心模块的授权配置提供器，安全模块涉及的url的授权配置在这里。
 * @Date: 2020/7/7 8:53
 */
@Component
public class DefaultAuthorizeConfigProvider implements AuthorizeConfigProvider {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public boolean config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry urlRegistry) {
        urlRegistry.antMatchers( SecurityConstants.DEFAULT_UNAUTHENTICATION_URL,
                SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_MOBILE,
                securityProperties.getBrowser().getLoginPage(),
                SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX+"/*",
                securityProperties.getBrowser().getSignUpUrl(),
                securityProperties.getBrowser().getSingInSuccessUrl(),
                securityProperties.getBrowser().getSession().getSessionInvalidUrl()+".json",
                securityProperties.getBrowser().getSession().getSessionInvalidUrl()+".html")
                .permitAll();
        return false;
    }
}
